<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>联盟云商圈</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="__INDEX__/js/mui.min.js"></script>
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="__INDEX__/css/iconfont.css" />
		<link rel="stylesheet" href="__INDEX__/css/style.css" />
		<link rel="stylesheet" href="__INDEX__/css/mall.css" />	
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
		    <h1 class="mui-title">附近云商圈</h1>
		</header>
		<div class="mui-content fjysq_content">
			<div class="fjysq_lisbox">
				<div class="bt clearfix">
					<span class="left">名称</span>
					<span class="center">商圈</span>
					<span class="right">距离</span>
				</div>
				<ul class="fjsq_list" id='union_item'>
					
				</ul>
			</div>
			<button type="button" id='create_sq' class="fjysq_sbtn" style="display: none;">创建商圈</button> 
			<button type="button" id='my_sq' class="fjysq_sbtn" style="display: none;">我的商圈</button> 
		</div>
		<div id="allmap"></div>
	</body>
</html>
{include file="public/footer" /}
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.2&key=eef7f290ac06bdf05b246cebc8cb2fb6&callback=my_getAddress"></script>
<script src="__PUBLIC__/static/js/assist.js"></script>
<script type="text/javascript">
//获取用户当前地址
var map, geolocation;
function my_getAddress(){
    //加载地图，调用浏览器定位服务
    map = new AMap.Map('container', {
        resizeEnable: true
    });
    map.plugin('AMap.Geolocation', function() {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            buttonPosition:'RB'
        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
    });
    $('#container').hide();
    //解析定位结果
    function onComplete(data) {
    	var lng = '113.015137';
    	var lat = '25.772722';
    	var user_id = '{$user_id}';
    	if(data.position.getLng()){
    		lng = data.position.getLng();
    	}
    	if(data.position.getLat()){
    		lat = data.position.getLat();
    	}
    	$.ajax({
		   	type:"post",
		   	data:{
		   		longitude	: lng,
		   		latitude	: lat,
		   		user_id		: user_id
		   	},
		   	url:"{:url('index/member/union_list')}",
		   	success:function(data){
		   		var union_list = data.data;
		   		//检查当前用户是否创建联盟
		   		var is_create =  union_list.is_create;
		   		if(is_create == 1){
		   			$('#my_sq').show();
		   		}else{
		   			$('#create_sq').show();
		   		}
		   		
		   		var union_htm="";
		   		for(var i = 0;i<union_list.list.length;i++){
		   			
		   			var jl = union_list[i].juli;
			   		var unit='m'
			   		if(union_list[i].juli>1000){
			   			jl = union_list[i].juli/1000;
			   			unit = 'km';
			   		}
		   			
		   			var union_info_url = "/index/member/union_show?union_id="+union_list[i].id;
		   			union_htm = "<li class='clearfix'>"+
								"<a href='"+union_info_url+"'>"+
								"<span class='left'>"+union_list[i].name+"</span>"+
								"<span class='center'>"+union_list[i].sq_name+"</span>"+
								"<span class='right'>"+jl+unit+"</span></a></li>";
					$('#union_item').append(union_htm);
		   		}
		   	}
   		});
    }
}
	//创建商圈
	$('#create_sq').click(function(){
		location.href = 'union_add.html'
	});
	
	//修改商圈信息
	$('#my_sq').click(function(){
		location.href = 'union_edit.html'
	});



</script>

